# -*- coding: utf-8 -*-

# File Name： resize_img
# Description :
# Author : lirui
# create_date： 2022/6/6
# Change Activity:
import cv2


def _resize(img, shape):
    """

    Args:
        img:
        shape:

    Returns:

    """
    dtype = img.dtype
    # if dtype != np.uint8:
    #     img = img.astype(np.uint8)
    return cv2.resize(img, shape).astype(dtype)


def resize_img(img, shape=None, scale=None):
    """
    resize img

    Args:
        img:
        shape:(h,w)
        scale:

    Returns:

    """
    if shape is not None:
        return _resize(img, shape)
    if scale is not None:
        h, w = img.shape[:2]
        h, w = int(h * scale), int(w * scale)
        return _resize(img, (w, h))
    raise Exception('One of `shape` and `scale` cant be None.')
